{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4500000000000"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 质能方程\n",
    "def zhineng(m):\n",
    "    c = 300000\n",
    "    return m*(c*c)\n",
    "zhineng(50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[185, 428, 82, 397, 39, 282, 675, 481]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "mingwen = [1,4,0,3,0,2,6,4]\n",
    "mima = []\n",
    "\n",
    "for mw in mingwen:\n",
    "    mima.append(random.randint(mw*100, mw*100+99))\n",
    "print(mima)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最大值:  648\n",
      "最小值:  61\n",
      "平均值:  303.0\n",
      "方差:  34300.5\n"
     ]
    }
   ],
   "source": [
    "def my_min(ps):\n",
    "    the_min = ps[0]\n",
    "    for p in ps:\n",
    "        if p < the_min:\n",
    "            the_min = p\n",
    "    return the_min\n",
    "def my_max(ps):\n",
    "    the_max = ps[0]\n",
    "    for p in ps:\n",
    "        if p > the_max:\n",
    "            the_max = p\n",
    "    return the_max\n",
    "def my_avg(ps):\n",
    "    the_sum = 0\n",
    "    for p in ps:\n",
    "        the_sum += p\n",
    "    return the_sum / len(ps)\n",
    "def fangcha(ps):\n",
    "    the_sum = 0\n",
    "    avg = my_avg(ps)\n",
    "    for p in ps:\n",
    "        the_sum += (avg-p)**2\n",
    "    return the_sum / len(ps)\n",
    "\n",
    "print('最大值: ', my_max(mima))\n",
    "print('最小值: ', my_min(mima))\n",
    "print('平均值: ', my_avg(mima))\n",
    "print('方差: ', fangcha(mima))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 0, 3, 0, 2, 6, 4]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def jiemi(mima): # 参数 parameter\n",
    "    mingwen = []\n",
    "    for m in mima:\n",
    "        mingwen.append(int(m / 100))\n",
    "    return mingwen\n",
    "jiemi(mima) # 引数 argument"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['学1楼', '学2楼', '学3楼', '学4楼', '学5楼', '学6楼', '学7楼', '学8楼', '学9楼', '学10楼', '学11楼', '学12楼', '学13楼', '学14楼', '学15楼', '学16楼', '学17楼', '学18楼']\n"
     ]
    }
   ],
   "source": [
    "# 重载\n",
    "names = []\n",
    "for i in range(18):\n",
    "    names.append('学' + str(i+1) + '楼')\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['主楼平安', '逸夫楼平安']\n"
     ]
    }
   ],
   "source": [
    "def pingan(l):\n",
    "    ret = []\n",
    "    for i in l:\n",
    "        ret.append(i + '平安')\n",
    "    return ret\n",
    "print(pingan(['主楼', '逸夫楼']))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
